import re

import jsonpath
import requests


class CardBagApi(object):
    s = requests.Session()

    @classmethod
    def getcode(cls, req_data):
        res = CardBagApi.s.request('GET', 'https://didsy.acftu.org:39500/code/get-code',
                                    headers={'User-Agent': 'Mozilla/5.0'},
                                    params=req_data
                                    )
        # code = re.search('"code":"(.*?)"', res.text).group(1)
        # code1 = jsonpath.jsonpath(res.json(), '$.data.code')[0]
        # data = {"code": code, "code1": code1}
        return res


if __name__ == '__main__':
    res = CardBagApi.getcode('code')
